# Makefile for Yuma doc directory
#  
#   doc directory
#
# In order to make the documentation:
#
# 1) Install LibreOffice to make PDFS
# 2) Install writer2xhtml12 in /usr/bin/writer2xhtml12 to make HTMLS
# 3) Run 'make DOC=1' from this directory
#
# make clean will clear out the PDFS and HTMLS
#

ifndef PREFIX
    PREFIX=/usr
endif

DOC_INSTALL = $(DESTDIR)$(PREFIX)/share/doc/yuma

ODTS = $(wildcard yuma_docs/*.odt)

PDFS = $(patsubst yuma_docs/%.odt,yuma_docs/pdf/%.pdf,$(ODTS))


HTMLS = yuma_docs/html/dev/yuma-dev-manual.xhtml \
  yuma_docs/html/installation/yuma-installation-guide.xhtml \
  yuma_docs/html/netconfd/yuma-netconfd-manual.xhtml \
  yuma_docs/html/quickstart/yuma-quickstart-guide.xhtml \
  yuma_docs/html/user-cmn/yuma-user-cmn-manual.xhtml \
  yuma_docs/html/yangcli/yuma-yangcli-manual.xhtml \
  yuma_docs/html/yangdiff/yuma-yangdiff-manual.xhtml \
  yuma_docs/html/yangdump/yuma-yangdump-manual.xhtml

CONVERT_PDF = libreoffice --headless --convert-to pdf:writer_pdf_Export \
 --outdir yuma_docs/pdf

CONVERT_HTML = /usr/bin/writer2latex12/w2l -xhtml11 -config ./writer2xhtml_yuma.xml 

ifdef DOC
all: pdfs htmls
else
all:
endif

pdfs: makepdf $(PDFS)

htmls: makehtml $(HTMLS)

makepdf:
	mkdir -p yuma_docs/pdf

cleanpdf:
	rm -rf yuma_docs/pdf


makehtml:
	mkdir -p yuma_docs/html/dev
	mkdir -p yuma_docs/html/installation
	mkdir -p yuma_docs/html/netconfd
	mkdir -p yuma_docs/html/quickstart
	mkdir -p yuma_docs/html/user-cmn
	mkdir -p yuma_docs/html/yangcli
	mkdir -p yuma_docs/html/yangdiff
	mkdir -p yuma_docs/html/yangdump

cleanhtml:
	rm -rf yuma_docs/html/dev
	rm -rf yuma_docs/html/installation
	rm -rf yuma_docs/html/netconfd
	rm -rf yuma_docs/html/quickstart
	rm -rf yuma_docs/html/user-cmn
	rm -rf yuma_docs/html/yangcli
	rm -rf yuma_docs/html/yangdiff
	rm -rf yuma_docs/html/yangdump


yuma_docs/pdf/%.pdf: yuma_docs/%.odt
	$(CONVERT_PDF) $<

yuma_docs/html/dev/%.xhtml: yuma_docs/yuma-dev-manual.odt
	$(CONVERT_HTML) $< yuma_docs/html/dev/

yuma_docs/html/installation/%.xhtml: yuma_docs/yuma-installation-guide.odt
	$(CONVERT_HTML) $< yuma_docs/html/installation/

yuma_docs/html/netconfd/%.xhtml: yuma_docs/yuma-netconfd-manual.odt
	$(CONVERT_HTML) $< yuma_docs/html/netconfd/

yuma_docs/html/quickstart/%.xhtml: yuma_docs/yuma-quickstart-guide.odt
	$(CONVERT_HTML) $< yuma_docs/html/quickstart/

yuma_docs/html/user-cmn/%.xhtml: yuma_docs/yuma-user-cmn-manual.odt
	$(CONVERT_HTML) $< yuma_docs/html/user-cmn/

yuma_docs/html/yangcli/%.xhtml: yuma_docs/yuma-yangcli-manual.odt
	$(CONVERT_HTML) $< yuma_docs/html/yangcli/

yuma_docs/html/yangdiff/%.xhtml: yuma_docs/yuma-yangdiff-manual.odt
	$(CONVERT_HTML) $< yuma_docs/html/yangdiff/

yuma_docs/html/yangdump/%.xhtml: yuma_docs/yuma-yangdump-manual.odt
	$(CONVERT_HTML) $< yuma_docs/html/yangdump/


depend:

clean: cleanhtml cleanpdf

superclean: clean

uninstall: clean
	rm -f $(DOC_INSTALL)

ifdef DOC
# force additional manuals install if DOC=1
install: cmninstall manuals
else
# install just common
install: cmninstall
endif  # DOC

cmninstall:
	mkdir -p $(DOC_INSTALL)
	cp extra/AUTHORS $(DOC_INSTALL)
	cp extra/README $(DOC_INSTALL)
	cp extra/COPYRIGHT $(DOC_INSTALL)
	cp extra/yuma-legal-notices.pdf $(DOC_INSTALL)


manuals:
	mkdir -p $(DOC_INSTALL)
	cp yuma_docs/server-call-chain.txt $(DOC_INSTALL)
	(cd yuma_docs;tar cf t.tar --exclude=copy.sh --exclude=.svn index.html pdf html;mv t.tar $(DOC_INSTALL))
	(cd $(DOC_INSTALL);tar xf t.tar;rm t.tar)



distclean: superclean


.PHONY: all clean depend superclean install distclean uninstall pdfs \
	makepdf cleanpdf cmninstall manuals htmls makehtml cleanhtml

# prevent the make program from choking on all the symbols
# that get generated from autogenerated make rules
.NOEXPORT:



